- collapse_filters = query.persisted?
= form_tag url_for, method: 'get', id: 'query_form', class: 'hide-when-print'
  = hidden_field_tag 'set_filter', '1'
  fieldset#filters.collapsible class=('collapsed' if collapse_filters )
    legend = t(:label_filter_plural)
    div style=('display: none;' if collapse_filters)
      = render :partial => 'queries/filters', locals: {query: query}
  fieldset.collapsible.collapsed
    legend = t(:label_options)
    div style='display: none;'
      table
        tr
          td = t(:field_column_names)
          td = render_query_columns_selection query
        tr
          td
            label = t(:field_group_by)
          td
            = select_tag 'group_by', options_for_select([[]] + query.groupable_columns.collect { |c| [c.caption, c.name.to_s] }, query.group_by)
        = hidden_field_tag 't[]'
        - if query.available_totalable_columns.any?
          tr
            td = t(:label_total_plural)
            td = available_totalable_columns_tags query
  p.buttons
    = link_to t(:button_apply), '#', class: 'icon icon-checked js-query-apply'
    = link_to t(:button_clear), {set_filter: 1}, class: 'icon icon-reload'
    - if query.new_record? && User.current.allowed_to?(:save_queries, @project, global: true)
      = link_to t(:button_save), '#', class: 'icon icon-save js-query-save', data: {url: @project ? new_project_hourglass_query_path(@project) : new_hourglass_query_path, query_class: query_identifier}
    - if query && query.persisted? && query.editable_by?(User.current)
      = link_to t(:button_edit), edit_hourglass_query_path(query), class: 'icon icon-edit'
      = link_to t(:button_delete), hourglass_query_path(query), confirm: t(:text_are_you_sure), method: :delete, class: 'icon icon-del'

= error_messages_for query
